package com.easylinkin.linkappapi.grid.copy;

import cn.hutool.core.util.ObjectUtil;
import com.easylinkin.core.models.Operator;
import com.easylinkin.linkappapi.grid.entity.GridReportWeekDetail;
import com.easylinkin.linkappapi.grid.models.dto.GridReportWeekDetailSaveDTO;
import com.easylinkin.linkappapi.grid.models.vo.GridReportWeekDetailCollectVO;
import com.easylinkin.linkappapi.grid.models.vo.GridReportWeekDetailInfoVO;
import com.easylinkin.linkappapi.tenant.entity.LinkappTenant;

/**
 * @author kyj
 * @date 2024/5/21 10:36
 */
public class GridReportWeekDetailCopy {
    public static GridReportWeekDetail copyAndNew(GridReportWeekDetailSaveDTO dto) {

        GridReportWeekDetail entity = GridReportWeekDetail.builder()
                .reportId(dto.getReportId())
                .specialContentStatus(dto.getSpecialContentStatus())
                .nextWeekSpecialPlan(dto.getNextWeekSpecialPlan())
                .otherIssuesReport(dto.getOtherIssuesReport())
                .build();

        insertCopy(dto.getOperator(), entity);

        return entity;
    }

    public static void copy(GridReportWeekDetailInfoVO weekDetailInfoVO, GridReportWeekDetailCollectVO vo) {
        if (ObjectUtil.isNull(weekDetailInfoVO)) {
            return;
        }

        vo.setSubmitTime(weekDetailInfoVO.getCreateTime());
        vo.setSpecialContentStatus(weekDetailInfoVO.getSpecialContentStatus());
        vo.setNextWeekSpecialPlan(weekDetailInfoVO.getNextWeekSpecialPlan());
        vo.setOtherIssuesReport(weekDetailInfoVO.getOtherIssuesReport());
    }

    public static void copy(LinkappTenant linkappTenant, GridReportWeekDetailCollectVO vo) {
        if (ObjectUtil.isNull(linkappTenant)) {
            return;
        }

        vo.setPlatformProjectName(linkappTenant.getPlatformProjectName());
        vo.setConstructionUnit(linkappTenant.getConstructionUnit());
        vo.setShigongUnit(linkappTenant.getShigongUnit());
        vo.setConstructionControlUnit(linkappTenant.getConstructionControlUnit());
        vo.setProjectStatus(linkappTenant.getProjectStatus());
    }

    public static GridReportWeekDetail insertCopy(Operator operator, GridReportWeekDetail entity) {
        entity.setTenantId(operator.getTenantId());

        entity.setCreatorId(operator.getUserId());
        entity.setCreator(operator.getUsername());
        entity.setCreateTime(operator.getNow());

        updateCopy(operator, entity);

        return entity;
    }

    public static GridReportWeekDetail updateCopy(Operator operator, GridReportWeekDetail entity) {
        entity.setModifyId(operator.getUserId());
        entity.setModifier(operator.getUsername());
        entity.setModifyTime(operator.getNow());

        return entity;
    }
}
